<template>
	<div class="comments">
		<div class="comments-title">
			<span>用户评价</span>
			<span>更多</span>
		</div>
		<div class="comments-content">
			<div class="content-title">
				<img :src="avatar" alt="">
				<span>{{uname}}</span>
			</div>
			<div class="content-body">
				<div class="text">
					{{info.content}}
				</div>
				<div class="size">
					<span>{{time}}</span>
					<span>{{info.style}}</span>
				</div>
				<div class="show-img" v-if="showImg">
					<img :src="item" alt="" v-for="item in showImg">
				</div>
				<div  class="show-img" v-else>
					暂无图片
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	export default {
		name:'comments',
		props:{
			comments:Object
		},
		data(){
			return {
				info:{},
				time:'',
				showImg:null,
				avatar:'',
				uname:''
			}
		},
		watch:{
			comments(){
				this.info = this.comments.list[0];
				this.time = this.getTime(this.info.created);
				this.showImg = this.info.images;
				this.avatar = this.info.user.avatar;
				this.uname = this.info.user.uname;
			}
		},
		methods:{
			getTime(value){
				let date = new Date(parseInt(value))
				let y = date.getFullYear()
				let MM = date.getMonth() + 1
				MM = MM < 10 ? ('0' + MM) : MM
				let d = date.getDate()
				d = d < 10 ? ('0' + d) : d
				return y + '-' + MM + '-' + d 
			}
		}
	}
</script>

<style scoped="scoped">
	.comments{
		display: flex;
		flex-direction: column;
		justify-content: left;
		align-items: center;
		margin: 20px 8px;
		border-top: 1px solid #ccc;
		font-size: 0.426666rem;
	}
	.comments-title {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0.48rem 0;
		width: 100%;
		font-size: 0.48rem;
		font-weight: bold;
		border-bottom: 1px solid #ccc;
	}
	.comments-content,.content-title{
		display: flex;
		justify-content: center;
		align-items: flex-start;
	}
	.comments-content{
		flex-direction: column;
		padding: 0.266666rem 0;
		width: 100%;
	}
	.content-title img{
		width: 30px;
		height: 30px;
		background: yellow;
		border-radius: 0.213333rem;
	}
	.content-title span {
		line-height: 0.8rem;
		padding-left: 0.16rem;
		font-size: 0.48rem;
		font-weight: bold;
	}
	.content-body {
		width: 100%;
		padding: 0.533333rem 0;
		color: #777;
	}
	.text {
		line-height: 0.54rem;
	}
	.size {
		padding-top: 0.32rem;
	}
	.size span:last-child{
		padding-left: 0.213333rem;
	}
	.show-img {
		width: 100px;
		height: 100px;
		padding: 0.373333rem 0;
		overflow: hidden;
	}
	.show-img img {
		width: 100%;
		height: auto;
	}
</style>
